package Demo2;

import java.io.*;
import java.util.*;

public class CountNum {
    public static void main(String[] args) {
        File file = new File("examine/src/Demo2/work.txt");
        //创建一个链表搜集字符
        ArrayList<String> list = new ArrayList<>();
        HashMap<String, Integer> map = new HashMap<>();
        byte[] bytes = null;
        try (BufferedInputStream os = new BufferedInputStream(new FileInputStream(file))) {
            bytes = os.readAllBytes();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (bytes != null) {
            String s = new String(bytes);
            String[] s1 = s.split("[,\\s]+" );
            Collections.addAll(list, s1);
            /*for (String s2 : list) {
                System.out.println( s2);
            }*/
        }
        for (String s : list) {
            map.put(s, map.getOrDefault(s, 0) + 1);
        }
        //遍历,统计每个字符出现的次数
        for (Map.Entry<String, Integer> entry : map.entrySet())
            System.out.println("数字 " + entry.getKey() + " 出现" + entry.getValue() + "次");
    }
}
